# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
from itemadapter import ItemAdapter


class QiubaiproPipeline:

    fp = None
    # 重写父类的方法:该方法只在开始爬虫的时候调用一次
    def open_spider(self,spider):
        print('开始爬虫：')
        self.fp = open(r'E:\Python\test\入门训练营\scrapy框架\qiubaiPro\qiubaiPro\笑话.txt','w+',encoding='utf-8')

    # 专门处理item类型对象
    # 接收到的item对象
    # 每接收到一个item就会执行一次
    def process_item(self, item, spider):
        author = item['author']
        content = item['content']
        self.fp.write(author+content)
        return item

    def close_spider(self,spider):
        print('结束爬虫.')
        self.fp.close()




